package com.cyy.common.config.jackson;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * LocalDate JSON反序列化工具
 */
public class MyLocalDateDeserializer extends JsonDeserializer<LocalDate> implements BaseTimeDeserializer {

    @Override
    public LocalDate deserialize(JsonParser parser, DeserializationContext context) throws IOException {
        LocalDateTime localDateTime = this.getLocalDateTimeBySource(parser.getValueAsString());
        return localDateTime == null ? null : localDateTime.toLocalDate();
    }
}
